package com.controller;

import com.domain.Resume;
import com.domain.Student;
import com.service.ResumeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

@Controller
@RequestMapping("/resume")
public class ResumeController {

    @Autowired
    private ResumeService resumeService;

    @RequestMapping("/find/{cid}")
    public ModelAndView find(@PathVariable Integer cid) {
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("resume",resumeService.find());
        modelAndView.addObject("cid",cid);
        modelAndView.setViewName("resume");
        return modelAndView;
    }

    @PostMapping("/save")
    public ModelAndView save(Resume resume, HttpSession session) {
        ModelAndView modelAndView = new ModelAndView();
        Student student = (Student) session.getAttribute("user");
        resume.setSid(student.getSid());
        resumeService.save(resume);
        modelAndView.setViewName("resume");
        return modelAndView;
    }

    @RequestMapping("/look")
    public ModelAndView look(Resume resume, HttpSession session){
        ModelAndView modelAndView = new ModelAndView();
        Student student = (Student) session.getAttribute("user");
        resume.setSid(student.getSid());
        modelAndView.addObject("resume_find",resumeService.look(resume));
        modelAndView.setViewName("resume_find");
        return modelAndView;
    }

}
